package cz.proks.easyhelpdesk.gwt.restapi;

import java.util.Collection;

import com.google.gwt.json.client.JSONValue;

import cz.proks.easyhelpdesk.api.model.base.AnIdentifiableHelpdeskModel;
import cz.proks.easyhelpdesk.gwt.utils.JsonizerUtils;
import cz.proks.easyhelpdesk.gwt.utils.RestUtils;

public abstract class BaseHelpdeskRestApi<Domain extends AnIdentifiableHelpdeskModel> extends BaseRestApi<Domain>{   
    public final static String LIST_FOR_HELPDEKS_URL_PART = "/listForHelpdesk";   
    
    protected final String getListForHelpdeskUrl() {
        return getBaseDomainUrl() + LIST_FOR_HELPDEKS_URL_PART;
    }
    
    public void listForHelpdesk(Long helpdeskId, final DomainListCallback<Domain> callback) {
        RestUtils.makeRestRequest(getListForHelpdeskUrl() + "/" + helpdeskId, new RestUtils.Callback(callback) {
            
            @Override
            public void onSuccess(JSONValue val) {
                Collection<Domain> entities = JsonizerUtils.getListFromJsonArray(val, getDomainJsonizer());
                callback.onDomainListSuccess(entities);
            }
        });       
    }
}
